package com.rimi.service.impl;

import com.rimi.bean.UserBean;
import com.rimi.dao.UserDao;
import com.rimi.dao.impl.UserDaoImpl;
import com.rimi.service.UserService;

/**
 * @author jerry
 */
public class UserServiceImpl implements UserService {

    private UserDao userDao;

    public UserServiceImpl(){
        userDao=new UserDaoImpl();
    }

    /**
     * @param email    邮箱
     * @param password 密码
     * @return
     *  查询到数据则返回对象
     *  则返回
     */
    @Override
    public UserBean login(String email, String password) {
        UserBean userBean = userDao.selectUserByEmail(email);
        //用户找不到
        if(userBean == null){
            return null;
        }
        //密码错误
        if(!userBean.getUserPassword().equals(password)){
            return null;
        }
        return userBean;
    }

    @Override
    public UserBean getUserById(Integer id) {
        return userDao.selectUserById(id);
    }

    @Override
    public UserBean getUserByToken(String token) {
        return userDao.selectUserByToken(token);
    }
}
